#include <list>
#include "GLibInit.h"
#include "GEventWrapper.h"
#include "GCritSecWrapper.h"
#include "GThreadPoolWrapper.h"

class CGThreadPoolProcessTest : public CGThreadPoolProcess
{
public:
  CGThreadPoolProcessTest(gulong id) : m_id(id)
  {
    g_print("CGThreadPoolProcessTest(%lu)\n", m_id);
  }
  virtual ~CGThreadPoolProcessTest()
  {
    g_print("~CGThreadPoolProcessTest(%lu)\n", m_id);
  }
  gulong RunProcess()
  {
    g_print("RunThread(%lu) %p starts!\n", m_id, this);
    g_usleep(G_USEC_PER_SEC * 5);
    g_print("RunThread(%lu) %p ends!\n", m_id, this);

    return 0;
  }

protected:
  gulong m_id;
};


static void TestThreadPool1()
{
  CGThreadPoolWrapper threadPool("threadpool_1");
  threadPool.CreatePool(5, TRUE);

  CGThreadPoolProcessTest *process;
  for(int i=0; i<10; i++)
  {
    process = new CGThreadPoolProcessTest(i);
    threadPool.Submit(process, TRUE);
    g_usleep(G_USEC_PER_SEC/10);
  }

  threadPool.Push();

  threadPool.DestroyPool(TRUE, TRUE);
}

void AddTestThreadPool()
{
  g_test_add_func("/threadpool/threadpool1", TestThreadPool1);
}